const uploadFiles = {
  state: {
    fileList: [],
    moduleState: 0 // 上传框状态 0.关闭，1.最小化，2.最大化
  },
  mutations: {
    AddFileItem: (state, fileItem) => {
      state.fileList.unshift(fileItem)
    },
    ClearFileList: (state) => {
      state.fileList = []
    },
    /**
     * 更新上传进度百分比
     * @param state
     * @param event
     * @param uid
     * @constructor
     */
    UpdateFileListPercentage: (state, {event, uid}) => {
      state.fileList.map(item => {
        if (item.uid === uid) {
          item.percentage = Math.floor(event.loaded / event.total * 100)
        }
      })
    },
    /**
     * 设置文件上传状态
     * @param state
     * @param uid
     * @param {string} status 成功：success，失败：failed，取消：cancel，上传中：uploading
     * @constructor
     */
    SetFileStatus: (state, {uid, status}) => {
      state.fileList.map(item => {
        if (item.uid === uid) {
          item.status = status
        }
      })
    },
    /**
     * 设置上传框状态
     * @param state
     * @param {number} moduleState 0.关闭，1.最小化，2.最大化
     * @constructor
     */
    SetModuleState: (state, {moduleState}) => {
      state.moduleState = moduleState
    }
  },
  actions: {},
}
export default uploadFiles
